//
//  FunOCRAppDelegate.m
//  FunOCR
//
//  Created by Luke Du on 8/03/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "FunOCRAppDelegate.h"
#import <SystemConfiguration/SCNetworkReachability.h>

#import "Reachability.h"


@implementation FunOCRAppDelegate

@synthesize window;
@synthesize tabBarController;
@synthesize setting;
@synthesize currentEntry;

- (void)dealloc {
    [tabBarController release];
    [window release];
	[setting release];
	[currentEntry release];
	
	
    [super dealloc];
}





- (void)applicationDidFinishLaunching:(UIApplication *)application {
    
    // Add the tab bar controller's current view as a subview of the window
    [window addSubview:tabBarController.view];
	
	
}




- (GDataServiceGoogleDocs *)docsService {

	static GDataServiceGoogleDocs* service = nil;
	
	if (!service) {
		service = [[GDataServiceGoogleDocs alloc] init];
		
		[service setShouldCacheDatedData:YES];
		[service setServiceShouldFollowNextLinks:YES];
	}
	
	NSLog(@"setting :: %@", self.setting);
	
	// update the username/password each time the service is requested
	NSString *username = [setting objectForKey:@"username"];
	NSString *password = [setting objectForKey:@"password"];

	
	if ([username length] && [password length]) {
		[service setUserCredentialsWithUsername:username
									   password:password];
	} else {
		[service setUserCredentialsWithUsername:nil
									   password:nil];
	}
	
	return service;
}






- (BOOL) isServerReachable
{
	
	
	BOOL _isDataSourceAvailable = YES;
	
	
	Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
	
	NetworkStatus internetStatus = [r currentReachabilityStatus];
	
	if ((internetStatus != ReachableViaWiFi) && (internetStatus != ReachableViaWWAN))
	{
		_isDataSourceAvailable = NO;
	} 
	
	return _isDataSourceAvailable;
}



@end

